// pages/person/person.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    columns:['男','女'],
    phone:'',
    name:'',
    sex:0 || wx.getStorageSync("sex") * 1,
    birthday:"2021-01-01",
  },
  onChange(e) {
    this.setData({
      [e.currentTarget.dataset.prop]:e.detail.value
    });
  },
  pickSex: function(e) {
    this.setData({
        sex: e.detail.value
    });
    // console.log("当前选择性别-sex", e.detail.value);
},
bindDateChange: function(e) {
  this.setData({
    birthday: e.detail.value
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    var name = options.name;
    var phone = options.phone;
    if(name =='微信用户'){
      name = '';
    }
    if (phone == 'null' || phone =='' || phone == null){
      phone = '';
    }
    var sex = options.sex;
    if (sex =='' || sex == 'null' || sex == null){
      sex = 0;
    }
    var birthday = options.birthday;
    if (birthday == 'null' || birthday =='' || birthday == null){
      birthday = '2021-01-01';
    }
    that.setData({
      name:name,
      phone:phone,
      sex:sex,
      birthday:birthday
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  finshSave(){
    var that = this;
    var openId= wx.getStorageSync('openid');
    if (that.data.name==''){
      wx.showToast({
        title: '请输入用户名',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    if (that.data.phone==''){
      wx.showToast({
        title: '请输入手机号',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    wx.request({ 
      url: 'https://pnst.tsintell.com/customer/saveCustomer',  
      //url: 'http://localhost:8066/customer/saveCustomer',  
      //url: 'http://124.71.238.22:8099/customer/saveCustomer', 
      method: 'POST', 
      data:{ 
        openId :openId, 
        name : that.data.name, 
        phone:that.data.phone,
        sex:that.data.sex,
        birthday:that.data.birthday
      }, 
      header: {//定死的格式，不用改，照敲就好 
        'Content-Type': 'application/x-www-form-urlencoded', 
      }, 
      success: function (res) {//这里写调用接口成功之后所运行的函数 
        var code = res.data.code; 
        if(code == 200){ 
          wx.setStorageSync('phone', that.data.phone) 
        wx.switchTab({ 
          url: '/pages/mine/mine', 
        }); 
        } 
      }, 
      fail: function (res) {//这里写调用接口失败之后所运行的函数 
        console.log('.........fail..........'); 
        console.log(res) 
      } 
    }) 
  }
})